package com.agile.leetcode.hutool.convert;

import cn.hutool.core.convert.Convert;
import org.junit.Test;

import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Date;

/**
 * @Author KD
 * @Date 2021/2/1 15:17
 */
public class ConvertDemo {
    /**
     * 转换为指定类型的数组
     */
    @Test
    public void test1() {
        String[] strArray = {"1", "2"};
        Integer[] intArray = Convert.toIntArray(strArray);
        for (Integer integer : intArray) {
            System.out.println(integer);
        }
    }

    /**
     * 16进制的转换
     */
    @Test
    public void test2() {
        String name = "陈彰坤";
        // 根据源码，其默认是utf-8编码集
        byte[] bytes = name.getBytes();
        String hex = Convert.toHex(name.getBytes());
        System.out.println(hex);
        // 转回字符串
        String s = Convert.hexToStr(hex, StandardCharsets.UTF_8);
        System.out.println(s);
    }

    /**
     * unicode的转换
     */
    @Test
    public void test3() {
        //
        String name = "陈彰坤";
        byte[] bytes = name.getBytes();
        String s = Convert.strToUnicode(name);
        System.out.println(s);
        String s1 = Convert.unicodeToStr(s);
        System.out.println(s1);
    }

    /**
     * 金额大小写的转换
     */
    @Test
    public void test4() {
        // 金额大小写的转换
        double l = 14.75;
        String s = Convert.digitToChinese(l);
        System.out.println(s);
    }

    /**
     * 数组类型转换
     */
    @Test
    public void test5() {
        String[] b = {"1", "2", "3", "4"};
        //结果为Integer数组
        Integer[] intArray = Convert.toIntArray(b);
        System.out.println(Arrays.toString(intArray));
        long[] c = {1, 2, 3, 4, 5};
        //结果为Integer数组
        Integer[] intArray2 = Convert.toIntArray(c);
        System.out.println(Arrays.toString(intArray2));
    }

    /**
     * 日期转换
     */
    @Test
    public void test6(){
        String dateStr="2023-12-12";
        Date date = Convert.toDate(dateStr);
        System.out.println(date.getTime());

        LocalDateTime localDateTime = Convert.toLocalDateTime(dateStr);
        System.out.println(localDateTime.getYear());
        System.out.println(localDateTime.getDayOfMonth());
    }

    /**
     * 金额的中文转换
     */
    @Test
    public void test7(){
        double a = 67556.32D;
        System.out.println(Convert.digitToChinese(a));
    }

    /**
     * 数字转中文
     */
    @Test
    public void test8(){
        String format1 = Convert.numberToChinese(1200, false);
        System.out.println(format1);
    }
}
